package com.danielepelagatti.flickrmanager.commands.photo
{
	import com.adobe.webapis.flickr.Photo;
	import com.adobe.webapis.flickr.events.FlickrResultEvent;
	import com.danielepelagatti.flickrmanager.commands.CommandHelper;
	import com.danielepelagatti.flickrmanager.commands.FlickrCommand;
	import com.danielepelagatti.flickrmanager.commands.IFlickrCommand;
	import com.danielepelagatti.flickrmanager.model.LocalUser;
	import com.theriabook.utils.Logger;
	import com.danielepelagatti.utils.ObjectCloner;
	import com.adobe.webapis.flickr.methodgroups.Tags;
	/**
	 * 
	 * @author redde
	 * 
	 */
	public class SetTags extends FlickrCommand implements IFlickrCommand
	{
		/**
		 * 
		 * @param event
		 * @return 
		 * 
		 */		
		public function error(event:FlickrResultEvent):Boolean
		{
			return false;
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		public function success(event:FlickrResultEvent):void
		{
			var result:Photo = event.data.photo as Photo;
			var pending:Photo = CommandHelper.getPhotoForOperation(event.type,result.id);
			
			if(pending)
			{
				var photo:Photo = LocalUser.getInstance().photoCollection.getPhotoById(result.id);
				
				var newTags:Array = [];
				for (var i:String in pending.tags)
					newTags.push(pending.tags[i]);
				
				photo.tags = newTags;
				
				CommandHelper.removePhotoOperation(event.type,pending);
			}
			else
				Logger.error("SetTags:: The result photo "+result.id+" doesn't correspond to any pending operation")
		}
		/**
		 * 
		 * @return 
		 * 
		 */		
		public function getAPICall():Function
		{
			return flickr.photos.setTags;
		}
		
	}
}